package com.yunxin.core.infra.common.channel.utils;

import com.yunxin.core.application.command.channel.ChannelCustomerApplyLibraryCommand;
import com.yunxin.core.domain.model.channel.ChannelPromotionApiCustomerConfig;
import com.yunxin.core.infra.common.channel.enums.ChannelPromtionCustomSwitchStatusEnum;
import com.yunxin.core.utils.infra.utils.AttributeDetermineUtils;

/**
 * @author zero°
 * @since 2023-07-04
 */
public enum ChannelCustomerAttributeDetermineUtils {

    /**
     * 实例
     */
    X;

    /**
     * 客户属性匹配
     * @param channelCustomerApplyLibrary channelCustomerApplyLibrary
     * @param channelPromotionApiCustomerConfig channelPromotionApiCustomerConfig
     * @return boolean
     */
    public boolean isMatchResult(ChannelCustomerApplyLibraryCommand channelCustomerApplyLibrary,
                                 ChannelPromotionApiCustomerConfig channelPromotionApiCustomerConfig) {
        //年龄按段
        boolean ageResult = isAgeResult(channelPromotionApiCustomerConfig, channelCustomerApplyLibrary.getAge());
        //教育程度判断
        boolean educationResult = isResult(channelPromotionApiCustomerConfig.getEducationLeveSwitch(), channelCustomerApplyLibrary.getEducationLevel(), channelPromotionApiCustomerConfig.getEducationLevels());
        //社保判断
        boolean socialSecurityResult = isSocialSecurityResult(channelPromotionApiCustomerConfig.getSocialSecuritySwitch(), channelCustomerApplyLibrary.getSocialSecurityLevel(), channelPromotionApiCustomerConfig.getSocialSecurityLevels());
        //公积金判断
        boolean accumulationFundResult = isAccumulationFundResult(channelPromotionApiCustomerConfig.getAccumulationFundSwitch(), channelCustomerApplyLibrary.getAccumulationFundLevel(), channelPromotionApiCustomerConfig.getAccumulationFundLevels());
        //芝麻分判断
        boolean sesameSeedResult = isResult(channelPromotionApiCustomerConfig.getSesameSeedQuotaSwitch(), channelCustomerApplyLibrary.getSesameSeedQuota(), channelPromotionApiCustomerConfig.getSesameSeedQuotas());
        //信用卡判断
        boolean creditCardResult = isCreditCardResult(channelPromotionApiCustomerConfig.getCreditCardSwitch(), channelCustomerApplyLibrary.getCreditCard(), channelPromotionApiCustomerConfig.getCreditCards());
        //房产判断
        boolean houseResult = isHouseResult(channelPromotionApiCustomerConfig.getHouseLevelSwitch(), channelCustomerApplyLibrary.getHouseLevel(), channelPromotionApiCustomerConfig.getHouseLevels());
        //车产判断
        boolean vehicleResult = isVehicleResult(channelPromotionApiCustomerConfig.getVehicleLevelSwitch(), channelCustomerApplyLibrary.getVehicleLevel(), channelPromotionApiCustomerConfig.getVehicleLevels());
        //保险判断
        boolean insureResult = isInsureResult(channelPromotionApiCustomerConfig.getInsureSwitch(), channelCustomerApplyLibrary.getInsure(), channelPromotionApiCustomerConfig.getInsures());
        //职业判断
        boolean occupationResult = isResult(channelPromotionApiCustomerConfig.getOccupationSwitch(), channelCustomerApplyLibrary.getOccupation(), channelPromotionApiCustomerConfig.getOccupations());
        //职业收入判断
        boolean occupationIncomeResult = isResult(channelPromotionApiCustomerConfig.getOccupationIncomeSwitch(), channelCustomerApplyLibrary.getOccupationMonthlyIncome(), channelPromotionApiCustomerConfig.getOccupationIncomes());
        //京东白条额度判断
        boolean jdBtResult = isQuotaResult(channelPromotionApiCustomerConfig.getJdBtQuotaSwitch(), channelCustomerApplyLibrary.getJdBtQuota(), channelPromotionApiCustomerConfig.getJdBtQuotas());
        // 蚂蚁花呗判断
        boolean antCreditPayResult = isQuotaResult(channelPromotionApiCustomerConfig.getAntCreditPayQuotaSwitch(), channelCustomerApplyLibrary.getAntCreditPayQuota(), channelPromotionApiCustomerConfig.getAntCreditPayQuotas());
        //微粒贷判断
        boolean microLoanResult = isQuotaResult(channelPromotionApiCustomerConfig.getMicroLoanQuotaSwitch(), channelCustomerApplyLibrary.getMicroLoanQuota(), channelPromotionApiCustomerConfig.getMicroLoanQuotas());
        //性别判断
        boolean sexResult = isResult(channelPromotionApiCustomerConfig.getSexSwitch(), channelCustomerApplyLibrary.getSex(), channelPromotionApiCustomerConfig.getSexes());
        //逾期判断
        boolean beOverdueResult = isBeOverdueResult(channelPromotionApiCustomerConfig.getBeOverdueSwitch(), channelCustomerApplyLibrary.getBeOverdue(), channelPromotionApiCustomerConfig.getBeOverdue());
        //城市判断
        boolean cityResult = isCityResult(channelCustomerApplyLibrary.getCity(), channelPromotionApiCustomerConfig.getCityConfig());
        //最终结果判断
        return ageResult && educationResult && socialSecurityResult && accumulationFundResult && sesameSeedResult
                && creditCardResult && houseResult && vehicleResult && insureResult && occupationResult && occupationIncomeResult
                && jdBtResult && antCreditPayResult && microLoanResult && sexResult && beOverdueResult && cityResult;
    }

    /**
     * 年龄判断
     *
     * @param channelPromotionApiCustomerConfig channelPromotionApiCustomerConfig
     * @param age                               age
     * @return boolean
     */
    private boolean isAgeResult(ChannelPromotionApiCustomerConfig channelPromotionApiCustomerConfig, Integer age) {
        boolean ageResult = true;
        if (ChannelPromtionCustomSwitchStatusEnum.CLOSE.getValue().equals(channelPromotionApiCustomerConfig.getAgeSwitch())) {
            return ageResult;
        }
        return AttributeDetermineUtils.X.isAgeResult(channelPromotionApiCustomerConfig.getCustomMinAge(), channelPromotionApiCustomerConfig.getCustomMaxAge(), age);
    }

    /**
     * 属性判断(= 教育程度、芝麻分、职业、职业收入、性别、逾期)
     *
     * @param switchStatus              switchStatus
     * @param customerAttribute         customerAttribute
     * @param channelCustomerAttributes channelCustomerAttributes
     * @return boolean
     */
    private boolean isResult(Integer switchStatus, Integer customerAttribute, String channelCustomerAttributes) {
        if (ChannelPromtionCustomSwitchStatusEnum.CLOSE.getValue().equals(switchStatus)) {
            return true;
        }
        return AttributeDetermineUtils.X.isResult(customerAttribute, channelCustomerAttributes);
    }

    /**
     * 额度属性判断(= 京东白条、蚂蚁花呗、微粒贷)
     *
     * @param switchStatus                   switchStatus
     * @param customerQuotaAttribute         customerQuotaAttribute
     * @param channelCustomerQuotaAttributes channelCustomerQuotaAttributes
     * @return boolean
     */
    private boolean isQuotaResult(Integer switchStatus, Integer customerQuotaAttribute, String channelCustomerQuotaAttributes) {
        if (ChannelPromtionCustomSwitchStatusEnum.CLOSE.getValue().equals(switchStatus)) {
            return true;
        }
        return AttributeDetermineUtils.X.isQuotaResult(customerQuotaAttribute, channelCustomerQuotaAttributes);
    }

    /**
     * 社保判断
     *
     * @param switchStatus                  switchStatus
     * @param customerSocialSecurity        customerSocialSecurity
     * @param channelCustomerSocialSecurity channelCustomerSocialSecurity
     * @return boolean
     */
    private boolean isSocialSecurityResult(Integer switchStatus, Integer customerSocialSecurity, String channelCustomerSocialSecurity) {
        if (ChannelPromtionCustomSwitchStatusEnum.CLOSE.getValue().equals(switchStatus)) {
            return true;
        }
        return AttributeDetermineUtils.X.isSocialSecurityResult(customerSocialSecurity, channelCustomerSocialSecurity);
    }

    /**
     * 公积金判断
     *
     * @param switchStatus                     switchStatus
     * @param customerAccumulationFund         customerAccumulationFund
     * @param channelCustomerAccumulationFunds channelCustomerAccumulationFunds
     * @return boolean
     */
    private boolean isAccumulationFundResult(Integer switchStatus, Integer customerAccumulationFund, String channelCustomerAccumulationFunds) {
        if (ChannelPromtionCustomSwitchStatusEnum.CLOSE.getValue().equals(switchStatus)) {
            return true;
        }
        return AttributeDetermineUtils.X.isAccumulationFundResult(customerAccumulationFund, channelCustomerAccumulationFunds);
    }


    /**
     * 信用卡判断
     *
     * @param switchStatus               switchStatus
     * @param customerCreditCard         customerCreditCard
     * @param channelCustomerCreditCards channelCustomerCreditCards
     * @return boolean
     */
    private boolean isCreditCardResult(Integer switchStatus, Integer customerCreditCard, String channelCustomerCreditCards) {
        if (ChannelPromtionCustomSwitchStatusEnum.CLOSE.getValue().equals(switchStatus)) {
            return true;
        }
        return AttributeDetermineUtils.X.isCreditCardResult(customerCreditCard, channelCustomerCreditCards);
    }


    /**
     * 房产判断
     *
     * @param switchStatus          switchStatus
     * @param customerHouse         customerHouse
     * @param channelCustomerHouses channelCustomerHouses
     * @return boolean
     */
    private boolean isHouseResult(Integer switchStatus, Integer customerHouse, String channelCustomerHouses) {
        if (ChannelPromtionCustomSwitchStatusEnum.CLOSE.getValue().equals(switchStatus)) {
            return true;
        }
        return AttributeDetermineUtils.X.isHouseResult(customerHouse, channelCustomerHouses);
    }

    /**
     * 车产判断
     *
     * @param switchStatus            switchStatus
     * @param customerVehicle         customerVehicle
     * @param channelCustomerVehicles channelCustomerVehicles
     * @return boolean
     */
    private boolean isVehicleResult(Integer switchStatus, Integer customerVehicle, String channelCustomerVehicles) {
        if (ChannelPromtionCustomSwitchStatusEnum.CLOSE.getValue().equals(switchStatus)) {
            return true;
        }
        return AttributeDetermineUtils.X.isVehicleResult(customerVehicle, channelCustomerVehicles);
    }

    /**
     * 保险判断
     *
     * @param switchStatus           switchStatus
     * @param customerInsure         customerInsure
     * @param channelCustomerInsures channelCustomerInsures
     * @return boolean
     */
    private boolean isInsureResult(Integer switchStatus, Integer customerInsure, String channelCustomerInsures) {
        if (ChannelPromtionCustomSwitchStatusEnum.CLOSE.getValue().equals(switchStatus)) {
            return true;
        }
        return AttributeDetermineUtils.X.isInsureResult(customerInsure, channelCustomerInsures);
    }

    /**
     * 逾期判断
     *
     * @param switchStatus             switchStatus
     * @param customerBeOverdue        customerBeOverdue
     * @param channelCustomerBeOverdue channelCustomerBeOverdue
     * @return boolean
     */
    private boolean isBeOverdueResult(Integer switchStatus, Integer customerBeOverdue, String channelCustomerBeOverdue) {
        if (ChannelPromtionCustomSwitchStatusEnum.CLOSE.getValue().equals(switchStatus)) {
            return true;
        }
        return AttributeDetermineUtils.X.isBeOverdueResult(customerBeOverdue, channelCustomerBeOverdue);
    }

    /**
     * 城市判断
     *
     * @param customerCity              customerCity
     * @param channelCustomerCityConfig channelCustomerCityConfig
     * @return boolean
     */
    private boolean isCityResult(String customerCity, String channelCustomerCityConfig) {
        return AttributeDetermineUtils.X.isCityResult(customerCity, channelCustomerCityConfig);
    }
}
